package com.example.reactor;

import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;

@Slf4j
public class Practice15 {

    public static void main(String[] args) {

        Practice15 practice15 = new Practice15();
        Integer num = 11;

        practice15.fun1(num)
                .flatMap(
                        i -> {
                            log.info("进入了flatmap i = {}", i);
                            return practice15.fun2();
                        }
                ).switchIfEmpty(
                        practice15.fun2()
                ).subscribe();

    }

    private Mono<Integer> fun1(Integer num) {
        if (num > 0) {
            log.info("fun1 {}  返回num", num);
            return Mono.just(num);
        } else {
            log.info("fun1 {} 返回空", num);
            return Mono.empty();
        }
    }

    private Mono<Void> fun2() {
        log.info("执行fun2");
        return Mono.empty();
    }

    private Mono<Void> fun3() {
        log.info("执行fun3");
        return Mono.empty();
    }

}
